import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'

/**
 *注意：子菜单仅在路由children.length>=1时出现
 *详细信息请参见：https://panjiachen.github.io/vue-element-admin-site/guide/essentials/router-and-nav.html
 *
 *隐藏：true如果设置为true，项目将不会显示在侧边栏中（默认值为false）
 *alwaysShow：true如果设置为true，将始终显示根菜单
 *如果未设置alwaysShow，则当项目具有多个子路由时，
 *它将变成嵌套模式，否则不显示根菜单
 *redirect:noRedirect如果设置为noRedirect，则不会在面包屑中重定向
 *name：'router-name'<keep-alive>使用的名称（必须设置！！！）
 *元：{
角色：['admin'，'editor']控制页面角色（您可以设置多个角色）
title：“title”侧边栏和面包屑中显示的名称（推荐集）
icon:“svg name”/“el-icon-x”侧边栏中显示的图标
breadcrumb：false如果设置为false，则该项将隐藏在breadcrug中（默认值为true）
activeMenu:'/example/list'如果设置了路径，侧边栏将突出显示您设置的路径
}
 */

/**
 *恒定路线
 *没有权限要求的基本页
 *可以访问所有角色
 */
export const constantRoutes = [
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },

  {
    path: '/404',
    component: () => import('@/views/404'),
    hidden: true
  },

  {
    path: '/',
    component: Layout,
    redirect: '/dashboard',
    children: [{
      path: 'dashboard',
      name: 'Dashboard',
      component: () => import('@/views/dashboard/index'),
      meta: { title: 'Dashboard', icon: 'dashboard' }
    }]
  },

]

export const asyncRoutes =[
  {
    path: '/application',
    component: Layout,
    children: [
      {
        path: 'index',
        name: 'Application',
        component: () => import('@/views/application/index'),
        meta: { title: '应用列表', icon: 'el-icon-s-grid',roles:['admin','salesman','plain'] }
      }
    ]
  },
  // {
  //   path: '/config',
  //   component: Layout,
  //   children: [
  //     {
  //       path: 'index',
  //       name: 'Application',
  //       component: () => import('@/views/config/index'),
  //       meta: { title: '应用配置', icon: 'el-icon-potato-strips',roles:['admin','salesman','plain'] }
  //     }
  //   ]
  // },
  {
    path: '/message',
    component: Layout,
    children: [
      {
        path: 'index',
        name: 'message',
        component: () => import('@/views/message/index'),
        meta: { title: '短信配置', icon: 'el-icon-chat-dot-round',roles:['admin','salesman','plain'] }
      }
    ]
  },
  // {
  //   path: '/activity',
  //   component: Layout,
  //   children: [
  //     {
  //       path: 'index',
  //       name: 'Activity',
  //       component: () => import('@/views/activity/index'),
  //       meta: { title: '活动时间', icon: 'el-icon-time',roles:['editor'] }
  //     }
  //   ]
  // },
  // {
  //   path: '/tinymce',
  //   component: Layout,
  //   children: [
  //     {
  //       path: 'index',
  //       name: 'Tinymce',
  //       component: () => import('@/views/tinymce/index'),
  //       meta: { title: 'Tinymce富文本', icon: 'el-icon-document',roles:['admin'] }
  //     }
  //   ]
  // },
  // {
  //   path: '/example',
  //   component: Layout,
  //   redirect: '/example/table',
  //   name: 'Example',
  //   meta: { title: '用户数据', icon: 'el-icon-s-help' },
  //   children: [
  //     {
  //       path: 'index',
  //       name: 'Table',
  //       component: () => import('@/views/table/index'),
  //       meta: { title: '数据列表', icon: 'table',roles:['admin','salesman','plain'] }
  //     },
  //     {
  //       path: 'appDataList',
  //       name: 'application',
  //       component: () => import('@/views/application/appDataList'),
  //       meta: { title: '数据列表2', icon: 'table',roles:['admin','salesman','plain'] }
  //     }
  //   ]
  // },

  {
    path: '/seting',
    component: Layout,
    meta: { title: '管理权限', icon: 'el-icon-s-tools' },
    children: [
      {
        path: 'admin',
        name: 'Admin',
        component: () => import('@/views/admin/index'),
        meta: { title: '账户设置', icon: 'user',roles:['admin','salesman','plain'] }
      },
      // {
      //   path: 'auth_group',
      //   name: 'AuthGroup',
      //   component: () => import('@/views/auth_group/index'),
      //   meta: { title: '角色权限', icon: 'tree' }
      // },
      // {
      //   path: 'auth_rule',
      //   name: 'AuthRule',
      //   component: () => import('@/views/auth_rule/index'),
      //   meta: { title: '权限规则', icon: 'tree' }
      // }
    ]
  },

  // {
  //   path: '/form',
  //   component: Layout,
  //   children: [
  //     {
  //       path: 'index',
  //       name: 'Form',
  //       component: () => import('@/views/form/index'),
  //       meta: { title: 'Form', icon: 'form' }
  //     }
  //   ]
  // },

  // {
  //   path: '/nested',
  //   component: Layout,
  //   redirect: '/nested/menu1',
  //   name: 'Nested',
  //   meta: {
  //     title: 'Nested',
  //     icon: 'nested'
  //   },
  //   children: [
  //     {
  //       path: 'menu1',
  //       component: () => import('@/views/nested/menu1/index'), // Parent router-view
  //       name: 'Menu1',
  //       meta: { title: 'Menu1' },
  //       children: [
  //         {
  //           path: 'menu1-1',
  //           component: () => import('@/views/nested/menu1/menu1-1'),
  //           name: 'Menu1-1',
  //           meta: { title: 'Menu1-1' }
  //         },
  //         {
  //           path: 'menu1-2',
  //           component: () => import('@/views/nested/menu1/menu1-2'),
  //           name: 'Menu1-2',
  //           meta: { title: 'Menu1-2' },
  //           children: [
  //             {
  //               path: 'menu1-2-1',
  //               component: () => import('@/views/nested/menu1/menu1-2/menu1-2-1'),
  //               name: 'Menu1-2-1',
  //               meta: { title: 'Menu1-2-1' }
  //             },
  //             {
  //               path: 'menu1-2-2',
  //               component: () => import('@/views/nested/menu1/menu1-2/menu1-2-2'),
  //               name: 'Menu1-2-2',
  //               meta: { title: 'Menu1-2-2' }
  //             }
  //           ]
  //         },
  //         {
  //           path: 'menu1-3',
  //           component: () => import('@/views/nested/menu1/menu1-3'),
  //           name: 'Menu1-3',
  //           meta: { title: 'Menu1-3' }
  //         }
  //       ]
  //     },
  //     {
  //       path: 'menu2',
  //       component: () => import('@/views/nested/menu2/index'),
  //       name: 'Menu2',
  //       meta: { title: 'menu2' }
  //     }
  //   ]
  // },

  // {
  //   path: 'external-link',
  //   component: Layout,
  //   children: [
  //     {
  //       path: 'https://panjiachen.github.io/vue-element-admin-site/#/',
  //       meta: { title: 'External Link', icon: 'link' }
  //     }
  //   ]
  // },

  // 404 page must be placed at the end !!!
  { path: '*', redirect: '/404', hidden: true }
]

const createRouter = () => new Router({
  // mode: 'history', // 需要服务支持
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
})

const router = createRouter()


// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher //重置路由器
}

export default router
